package com.zjj.learn.designmodel.principles.demo2.before;

/** 测试正方形不是长方形
 * 若将正方形定义为长方形时，则会违背里氏代换原则
 * *** @author zjj_admin
 * *** 2022/4/4 23:20
 */
public class RectangleTest {

    public static void main(String[] args) {

        Rectangle rectangle = new Rectangle();
        rectangle.setWidth(10);
        rectangle.setLength(25);
        //此处若使用正方形进行扩宽，程序将会一直执行下去
       /* Square square = new Square();
        square.setLength(10);
        square.setWidth(10);*/
        resize(rectangle);
        printLengthAndWidth(rectangle);
    }


    //长方形扩宽操作
    public static void resize(Rectangle rectangle){
        while (rectangle.getWidth() <= rectangle.getLength()){
            rectangle.setWidth(rectangle.getWidth() + 1);
        }
    }

    //打印长方形的长和宽
    public static void printLengthAndWidth(Rectangle rectangle){
        System.out.println("rectangle.getLength() = " + rectangle.getLength());
        System.out.println("rectangle.getWidth() = " + rectangle.getWidth());
    }
}
